package com.hp.gxw.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author huangping
 * @since 2023-10-17
 */
@Controller
@RequestMapping("/manage/settlement_order")
@Slf4j
public class SettlementOrderController {
//
//    @Autowired
//    private ICustomerService iCustomerService;
//
//    @Autowired
//    private IProductService iProductService;
//
//    @Autowired
//    private ISettlementOrderService iSettlementOrderService;
//
//    @Autowired
//    private ISettlementOrderDetailsService iSettlementOrderDetailsService;
//
//    @Autowired
//    private ISettlementOrderProcessService iSettlementOrderProcessService;
//
//    @Autowired
//    private ISaleOrderProcessService iSaleOrderProcessService;
//
//    @Autowired
//    private ISaleOrderService iSaleOrderService;
//
//    @Autowired
//    private ISaleOrderDetailsService iSaleOrderDetailsService;
//
//    @Autowired
//    private IProcessPriceOrderService iProcessPriceOrderService;
//
//    @Autowired
//    private IProcessPriceProduceService iProcessPriceProduceService;
//
//    @RequestMapping("/index")
//    public String index(Model model){
//        model.addAttribute("customer", iCustomerService.list());
//        return "settlement_order/index";
//    }
//
//    @RequestMapping("/addHtml")
//    public String addHtml(Model model){
//        return "settlement_order/add";
//    }
//
//    @RequestMapping("/addDetailHtml")
//    public String addDetailHtml(Model model){
//        return "settlement_order_details/add";
//    }
//
//    @RequestMapping("/addProcessHtml")
//    public String addProcessHtml(Model model){
//        return "settlement_order_details/add";
//    }
//
//    @RequestMapping("/infoHtml")
//    public String infoHtml(String id, Model model){
//        model.addAttribute("id", id);
//        return "settlement_order/info";
//    }
//
//    @RequestMapping("/list")
//    @ResponseBody
//    public LayTableR list(Integer page, Integer limit, String master) throws Exception {
//        QueryWrapper<SettlementOrder> ew = ConditionUtil.convert(master, new QueryWrapper<>());
//        ew.orderByDesc("create_time");
//        Page<SettlementOrder> pageList = iSettlementOrderService.page(new Page<>(page, limit), ew);
//        return LayTableR.result(0, pageList.getTotal(), pageList.getRecords());
//    }
//
//    @RequestMapping("/info")
//    @ResponseBody
//    public Object info(String masterId){
//        SettlementOrder settlementOrder = iSettlementOrderService.getById(masterId);
//        List<SettlementOrderDetails> detailsList = iSettlementOrderDetailsService.list(new LambdaQueryWrapper<SettlementOrderDetails>().eq(SettlementOrderDetails::getMasterId, masterId));
//        settlementOrder.setDetailsList(detailsList);
//        return settlementOrder;
//    }
//
//    @RequestMapping("/process_info")
//    @ResponseBody
//    public Object process_info(String detailsId) throws Exception{
//        QueryWrapper<SaleOrder> ew = new QueryWrapper<>();
//        ew.eq("a.id",detailsId);
//        List<SaleOrderProcess> processList = iSaleOrderService.getSettlementPrice(ew);
//
////        SettlementOrderDetails orderDetails = iSettlementOrderDetailsService.getById(detailsId);
////        SettlementOrder settlementOrder = iSettlementOrderService.getById(orderDetails.getMasterId());
////        Customer customer = iCustomerService.getOne(new LambdaQueryWrapper<Customer>().eq(Customer::getCode, settlementOrder.getCustomerCode()));
////        Product product = iProductService.getOne(new LambdaQueryWrapper<Product>().eq(Product::getCode, orderDetails.getCinvcode()));
////        SaleOrder saleOrder = iSaleOrderService.getOne(new LambdaQueryWrapper<SaleOrder>().eq(SaleOrder::getOrderNo, settlementOrder.getSaleOrderNo()));
////        List<SaleOrderProcess> processList = iSaleOrderProcessService.list(new LambdaQueryWrapper<SaleOrderProcess>().eq(SaleOrderProcess::getDetailsId, orderDetails.getDetailId()));
////        for(SaleOrderProcess saleOrderProcess : processList){
////            if(saleOrderProcess.getSettlementcost() == null){
////                saleOrderProcess.setSettlementcost(saleOrderProcess.getIoricost());
////            }
////        }
////        if(TypeEnum.exception_settlement.getCode().equals(orderDetails.getSettlementType())){
////            Iterator<SaleOrderProcess> iterator = processList.iterator();
////            while(iterator.hasNext()){
////                SaleOrderProcess saleOrderProcess = iterator.next();
////                ProcessPriceOrder priceOrder = iProcessPriceOrderService.getOne(new LambdaQueryWrapper<ProcessPriceOrder>()
////                        .eq(ProcessPriceOrder::getCustomerId, customer.getId())
////                        .eq(ProcessPriceOrder::getProductId, product.getId())
////                        .eq(ProcessPriceOrder::getType, orderDetails.getType())
////                        .eq(ProcessPriceOrder::getOrderProcessCode, saleOrderProcess.getOrderProcess()));
////
////                List<ProcessPriceProduce> produceList = iProcessPriceProduceService.list(new LambdaQueryWrapper<ProcessPriceProduce>()
////                        .eq(ProcessPriceProduce::getOrderId, priceOrder.getId()));
////                Set<String> set = produceList.stream().map(ProcessPriceProduce::getProduceProcessCode).collect(Collectors.toSet());
////                if(set.size() > 0){
////                    long count = iSettlementOrderProcessService.count(new LambdaQueryWrapper<SettlementOrderProcess>()
////                                    .eq(SettlementOrderProcess::getDetailsId, detailsId)
////                                    .in(SettlementOrderProcess::getProductProcess, set));
////                    if(count < 1){
////                        iterator.remove();
////                    }
////                }else {
////                    iterator.remove();
////                    log.error("工序价格对照表中出现对照不上的情况");
////                }
////            }
////        }
//        return processList;
//    }
//
//    @RequestMapping("/process_info_list")
//    @ResponseBody
//    public Object process_info_list(String detailsId) throws Exception{
//        QueryWrapper<SaleOrder> ew = new QueryWrapper<>();
//        ew.in("f.details_id", Arrays.asList(detailsId.split(",")));
//        return  iSaleOrderService.getSettlementPriceAdd(ew);
//    }
//
//    @PostMapping("/settlement_price_set")
//    @ResponseBody
//    public R settlement_price_set(String settleDetailId, String process,String type){
//        if (StringUtils.isEmpty(settleDetailId) || StringUtils.isEmpty(process) || StringUtils.isEmpty(type)){
//            return R.error("参数不完整");
//        }
//        try {
//            //判断是否已经定价
//            SettlementOrderDetails settlementOrderDetails = iSettlementOrderDetailsService.getById(settleDetailId);
//            if(settlementOrderDetails.getCompletFlag()){
//                return R.error("已经订过价");
//            }
//            //数据解析
//            List<SettlementOrderProcess> processList = JSON.parseArray(process, SettlementOrderProcess.class);
//            if (processList.isEmpty()){
//                return R.error("数据解析失败！");
//            }
//            iSaleOrderProcessService.settlementPriceSetNew(settleDetailId,processList,type);
//        }catch (Exception e){
//            e.printStackTrace();
//            return R.error();
//        }
//        return R.ok();
//    }
//
//
//    @RequestMapping("/add")
//    @ResponseBody
//    public R add(@RequestBody JSONObject jsonObject){
//        if (null == jsonObject || jsonObject.isEmpty()){
//            return R.error("未接收到数据！");
//        }
//        try {
//            iSettlementOrderService.add(jsonObject);
//        } catch (Exception e) {
//            return R.error(e.getMessage());
//        }
//        return R.ok();
//    }
//
//    @RequestMapping("/upd")
//    @ResponseBody
//    public R upd(@RequestBody JSONObject jsonObject){
//        if (null == jsonObject || jsonObject.isEmpty()){
//            return R.error("未接收到数据！");
//        }
//        try {
//            iSettlementOrderService.upd(jsonObject);
//        } catch (Exception e) {
//            return R.error(e.getMessage());
//        }
//        return R.ok();
//    }

}